/**
 * Created by smp on 2017/3/20.
 */
var isSearchBarExpand = false;
var index;

var modelPath=ROOT_PATH+'/permission/log/';
function doSearch(value, name) {
    alert('You input: ' + value + '(' + name + ')');
}
function toggleSearch() {
    var $mainLayout = $('#main_layout');
    var expandHeight = 200;
    var collapseHeight = 50;
    if (!isSearchBarExpand){
        $mainLayout.layout('panel','north').panel('resize',{height:expandHeight});
        $mainLayout.layout('resize');
        isSearchBarExpand = true;
    }
    else {
        $mainLayout.layout('panel','north').panel('resize',{height:collapseHeight});
        $mainLayout.layout('resize');
        isSearchBarExpand = false;
    }
}
$(function () {
    //初始化加载datagrid
    $('#loginLogList').datagrid({
        method: 'post',
        url: ROOT_PATH + '/permission/log/loginLogList.shtml',
        queryParams: {
            sort: 'loginTime',
            order: 'desc'
        },
        //idField: 'id',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        sortOrder: true,
        striped: true,
        fit: true,
        columns: [[
            {field: 'id', width: 80, checkbox: true,hidden:true},
            {
                field: 'loginUserName',
                title: '登录用户',
                width: 80,
                sortable: false,
                formatter: function (value, row, index) {
                    if (row.user&&row.user.name) {
                        return row.user.name;
                    } else {
                        return '';
                    }
                }
            },
            {
                field: 'loginUserRealName',
                title: '登录用户姓名',
                width: 80,
                sortable: false,
                formatter: function (value, row, index) {
                    if (row.user&&row.user.realName) {
                        return row.user.realName;
                    } else {
                        return '';
                    }
                }
            },
            {field: 'loginIp', title: '登录IP', width: 100,  sortable: true},
            {field: 'loginTime', title: '登录时间', width: 80,  sortable: true},
            {field: 'offlineTime', title: '下线时间', width: 80,  sortable: true},
            {field: 'remarks', title: '备注', width: 100, }
        ]],
        toolbar: '#toolbar'
    });
    /**
     * 查询按钮
     */
    $('#selectLoginLogList').on('click',function(){
        var name=$('#name').val();
        var loginTime=$('#loginTime').val();
        $('#loginLogList').datagrid('load', {name:name,loginTime:loginTime,sort: 'loginTime', order: 'desc'});
    });
    $("#btn_clear").on("click",function () {
        $('#tb1').form('reset');
    })
});